/*
 * timer.h
 *
 *  Created on: Nov 19, 2011
 *      Author: bendischinger
 */

#ifndef TIMER_H_
#define TIMER_H_

#ifdef __MAIN
#define __EXTERN
#else
#define __EXTERN extern
#endif

#ifdef __APPLE__
typedef unsigned long long test_time_t;
#endif

#define	UNIT_SEC  1
#define	UNIT_MSEC 1000
#define	UNIT_USEC 1000000
#define UNIT_NSEC 1000000000

typedef struct test_stat {
	double test_time;
	double read_time;
	double write_time;
	double op_time;

	int read_cnt;
	int write_cnt;
	int op_cnt;

	double helper_read_time;
	double helper_time;

	int helper_read_cnt;
	int helper_behind_cnt;
	int helper_ahead_cnt;

	double max_read_time;
	double max_write_time;
	double max_op_time;

	double min_read_time;
	double min_write_time;
	double min_op_time;

	int cache_hit;
	int cache_miss;
	int cache_pop;
	int cache_col;

	int aio_err;
	int aio_wait;
	int aio_eagain;
} test_stat_t;

__EXTERN test_stat_t global_stat;

#define MAX(a,b) ((a) >= (b) ? (a) : (b))
#define ASSIGN_MAX(a,b) a = MAX(a,b)

#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ASSIGN_MIN(a,b) a = MIN(a,b)

void init_test_stat(test_stat_t *stat);
test_time_t start_timer(void);
double stop_timer(test_time_t start, int unit);
double convert_time(double time, int from_unit, int to_unit);

#endif /* TIMER_H_ */
